package edu.cuc.akkaDay01.demo01;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;

/**
 * Created by bingruiqi on 2017/9/9.
 */
public class HelloWorld extends UntypedActor {
    ActorRef greeter;
    @Override
    public void onReceive(Object o) throws Exception {
        if (o==(Greeter.Msg.Done)) {
            greeter.tell(Greeter.Msg.GREET, getSelf());
            getContext().stop(getSelf());
        } else {
            unhandled(o);
        }
    }

    @Override
    public void preStart() throws Exception {
        greeter = context().actorOf(Props.create(Greeter.class),"greeter");
        System.out.println("Greeter Actor Path" + greeter.path());
        greeter.tell(Greeter.Msg.GREET,getSelf());
    }
}
